
var table;
var  $;
var laydate;
var layer;
var form;
layui.use(['table', 'laydate','layer','form'],function(){
        table = layui.table,
        $=layui.$,
        laydate=layui.laydate,
        layer=layui.layer,
        form=layui.form;

    $('#btn_1').click(function(){
        location.reload();
    });


    //课程分类下拉菜单
    selCourseClassSelect();
    function selCourseClassSelect(){
        $.ajax({
            url: "/SyOperationController/selCourseClassSelect",
            type: "get",
            dataType: "json",
            success: function (data) {
                for(var a=0;a<data.data.length;a++){
                    $("#course_cstatus").append("<option value='"+data.data[a].id+"'>"+data.data[a].name+"</option>");
                }
                form.render();
            }
        });
    }

    getCourseCheckTable();

});

function selCourse(){
    var courseName=$("#courseName").val();
    var name=$("#course_cstatus option:selected").val();
    var courseNprice=$("#courseNprice").val();
    getCourseCheckTable(courseName,name,courseNprice);
}





function getCourseCheckTable(courseName,name,courseNprice){
    $.ajax({
        url: '/courseCheck/selCourseCheck',
        type:"post",
        datatType:"json",
        data:{"courseName":courseName,"name":name,"courseNprice":courseNprice},
        success:function(data){
            CourseTable(data.data);
        }
    });
}

function CourseTable(data){
    table.render({
        elem: '#div_table'
        ,data:data
        ,page: true
        ,cols: [[ //表头
            {type:'checkbox'}
            ,{field: 'course_id', title: '编号', minWidth:60, align: 'center',templet: function (data) {
                    return data.LAY_INDEX;
                }}
            ,{field: 'url', title: '课程图片', width:130,align: 'center',templet:function(data){
                    if(data.url!=null){
                        return "<img src='"+data.url+"' style='height: 100px'>";
                    }else{
                        return "<span>无图片</span>"
                    }
                }}
            ,{field: 'course_name', title: '课程名称', minWidth:150, align: 'center'}
            ,{field: 'course_nprice', title: '价格', minWidth: 100, align: 'center'}
            ,{field: 'id', title: '分类编号', minWidth: 60, align: 'center'}
            ,{field: 'name', title: '分类', minWidth: 100, align: 'center'}
            ,{field: 'course_cstatus', title: '审核状态', align: 'center',minWidth: 100,templet:function(data){
                    if(data.course_cstatus=="4"){
                        return "审核中";
                    }else if(data.course_cstatus=="3"){
                        return "未审核";
                    }
                }}
            ,{field: '查看申请详情', title: '操作', minWidth: 100,align: 'center',templet:function(data){
                    return "<a href='#' onclick='javascript:Look(\""+data.course_id+"\",\""+data.type+"\")' style='color: #1ABC9C'>查看</a>&nbsp<a href='#' onclick='javascript:Check(\""+data.course_id+"\",\""+data.course_name+"\",\""+data.create_id+"\")' style='color: #1ABC9C'>审核</a>";
            }}
        ]]
    });
}


//审核
Check=function(course_id,course_name,userId){

    //获取当前登陆人员的信息
    var create=localStorage.getItem("user");
    create=JSON.parse(create);//将获取json字符串转json对象

    if(userId==create.user_id){
        layer.msg("无审核资格",{icon:5});
    }else{
        layer.open({
            type:2,
            title:"审核详情",
            area:['600px','400px'],
            shade:0.4,
            offset:'auto',
            content:"courseCheckson.html",
            success:function(layero,index){
                var obj = layero.find('iframe').contents();
                obj.find('input[name=forumId]').val(course_name);
                obj.find('input[name=ForumMId]').val(course_id);
            }
        });
    }

}

$("#div_super").on('click',function(){
    layer.open({
        type:2,//弹出层类型
        title:'高级检索',
        area:['700px','350px'],
        shade:0.5,
        content:"SuperCheck.html",
        offset:"auto"
    });
    window.layer_1=layer;
});

//点击查看按钮弹出详情页面
function Look(id,type){
    var index = layer.open({
        type:2,
        title:"课程详情",
        area:['800px','600px'],
        shade:0.4,
        offset:'auto',
        maxmin: true,
        content:"/operation/comment/TeaCourseView.html",
        success:function(layero,index) {
            //查找当前引入的iframe内容
            var obj = layero.find('iframe').contents();
            //根据选择器选择input,并设置值
            obj.find('input[name=courseId]').val(id);

            //获取类型
            obj.find('input[name=type]').val(type);
        }
    });
    layer.full(index);
}
function LookInfo(data){
    layer.open({
        type : 2,//弹出层的类型
        id:1,
        title : "<div style='color:#666666;font-weight: 600;background: #F8F8F8;'>课程详情</div>",
        area : [ '670px', '500px' ],
        maxmin: true,
        shade : 0,
        offset: 'auto',
        content :"CourseCheckInfo.html",
        success:function(layero,index){

            var obj=layero.find('iframe').contents();
            obj.find('input[name=course_id]').val(data.course_no);
            obj.find('input[name=course_name]').val(data.course_name);
            obj.find('input[name=course_nprice]').val(data.course_nprice);
            obj.find('input[name=id]').val(data.class_id);
            obj.find('input[name=name]').val(data.name);
            obj.find('input[name=sort]').val(data.sort);
            if(data.course_cstatus=="4"){
                obj.find('input[name=course_cstatus]').val(data.course_cstatus="审核中");
            }else if(data.course_cstatus=="3"){
                obj.find('input[name=course_cstatus]').val(data.course_cstatus="未审核");
            }
        }
    });
    window.layer_1=layer;
}
